import collections
class Solution(object):
    def numberOfSubstrings(self, s):
        c = collections.Counter(s)
        ans = 0
        for key in c:
            ans += c[key] + c[key] * (c[key] - 1) // 2
        return ans
